package mini.expr.math;

import java.util.LinkedList;
import java.util.List;

import mini.Env;
import mini.expr.Element;
import mini.expr.Expr;


public class Minus extends Expr {

    private Expr expr1,  expr2;

    public Minus(Expr op1, Expr op2) {
        expr1 = op1;
        expr2 = op2;
    }

    public Element eval(List<Env> listOfEnvs, LinkedList var) {
        Element val1 = expr1.eval(listOfEnvs, var);
		Element val2 = expr2.eval(listOfEnvs, var);
		
        if (!val1.isInt() || !val2.isInt()) {
        	throw new IllegalArgumentException("Parse error. Expression does not evaluate to an int.");
        }
        
		return new Element(val1.getIntValue() - val2.getIntValue());
    }
}